<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>operLog Index</title>
 	<%@ include file="/common/view/header.jsp"%>
  	<script>
  		var win=null, form=null, grid=null;
  		$(function(){
  			//create datagrid
			grid = $('#tt').datagrid({
                url:'<%=cp%>/rbac/getAllOperLog',
                pageSize:20,
    			pageList:[5,10,15,20],
    			loadMsg:'正在加载系统日志列表......',
    			pagination:true,
    			method:"post",
				height: document.body.clientHeight,
				striped: true,
				rownumbers:true,
                fitColumns: true,
                singleSelect: true,
                remoteSort:false,
                idField:'id',
                columns:[[
			        {title:'登录用户名',field:'loginUname',width:fixWidth(0.09),sortable:false,align:'left'},
			        {title:'操作时间',field:'operTime',width:fixWidth(0.12),sortable:false,align:'center'},
                	{title:'访问模块',field:'operMod',width:fixWidth(0.08),sortable:false,align:'left'},
                	{title:'事件',field:'operEvent',width:fixWidth(0.08),sortable:false,align:'left'},
                	{title:'IP地址',field:'operIp',width:fixWidth(0.10),sortable:false,align:'left'},
                	{title:'请求来源',field:'operFrom',width:fixWidth(0.16),sortable:false,align:'left'},
                	{title:'操作',field:'doaction',align:'center',width:fixWidth(0.08),align:'center',
						formatter:function(value,row,index){
							var e = '<a href="###" onclick="editDataItem('+index+')">详细</a> ';
							var d = '<a href="###" onclick="deleteRow('+index+')">删除</a>';
							return e+d;
						}
					}
				]],
                onDblClickRow:function(rowIndex, rowData){
                	editDataItem(rowIndex);
                },
				toolbar:[{
						id:'btnadd',
						text:'清空日志',
						iconCls:'icon-no',
						handler:deleteAllRows
					},'-',{
						text:'高级查询',
						iconCls:'icon-search',
						handler:openSearchForm
					},'-',{
						text:'显示全部',
						iconCls:'icon-reload',
						handler:displayAll
					},'-'
				]
            });
  			
  			//create searchbox and menu to toolbar
  			$("<td></td>").appendTo('.datagrid-toolbar table tr');
  			//$('.searchbox').appendTo('.datagrid-toolbar table td:last');
  			$('#q').appendTo('.datagrid-toolbar table td:last');
  			init_searchmenu();
  			
			//create window
			init_window();
			//create form
			init_form();
			//create datebox
		});
  		/* 初始化查询下拉菜单 */
  		function init_searchmenu(){
  			var fields = grid.datagrid('getColumnFields');
			for(var i=0; i<fields.length; i++){
				if(fields[i]!='operTime' && fields[i]!='doaction'){
					var opts = grid.datagrid('getColumnOption', fields[i]);  
					var muit = "<div name='"+  fields[i] +"'>"+ opts.title +"</div>";
					$('#mm').html($('#mm').html()+muit);
				}
			}
			$('#q').searchbox({
				menu:'#mm'
			});
  		}
  		/* 初始化窗口控件 */
  		function init_window(){
  			var width = 640;
  			var height = 450;
  			var top = (document.body.clientHeight-height)/2;
  			var left = (document.body.clientWidth-width)/2;
  			win = $('#data_win').window({
				closed:true,
				width: width,
				height: height,
				top: top,
  				left: left,
				modal: true,
				iconCls:'icon-app'
			});
  		}
  		/* 初始化表单控件 */
  		function init_form(){
  			form = win.find('form');
  		}
  		/* 装载数据项 */
  		function editDataItem(index){
  			var row = grid.datagrid('getRows')[index];
  			if (row){
  				win.window('setTitle','详细日志');
				win.window('open');
				form.form('clear');
				form.form('load', '<%=cp%>/rbac/getOperLog/'+row.id+'?rnd='+Math.random());
			} else {
				$.messager.show({
					title:'警告',
					msg:'请您先选择日志。'
				});
			}
  		}
  		/* 打开查询表单窗口 */
  		function openSearchForm(){
  			var width = 350;
  			var height = 130;
  			var top = (document.body.clientHeight-height)/2;
  			var left = (document.body.clientWidth-width)/2;
			$('#searchform').window({
				title: '高级查询',
				width: width,
				height: height,
				top: top,
  				left: left,
				modal: false,
				closed: false,
				minimizable:false,
      			maximizable:false,
      			collapsible:false,
				resizable:false,
				iconCls:'icon-search'
			});
		}
  		/* 关闭表单窗口 */
  		function closeWindow(){
			if(win)
				win.window('close');
		}
  		/* 执行查询 */
  		function do_search(){
			var btime = $('#btime').datebox('getValue');	//提交中文参数一定使用encodeURI函数进行编码
			if(btime==''){
				$.messager.alert('提示','请您选择开始时间','error');
				return;
			}
			var etime = $('#etime').datebox('getValue');
			if(etime==''){
				$.messager.alert('提示','请您选择结束时间','error');
				return;
			}
			if(!compareTime(btime,etime)){
				$.messager.alert('提示','请注意开始时间必须小于结束时间','error');
				return;
			}
			grid.datagrid('options').queryParams = {btime:btime+" 00:00:00", etime:etime+" 23:59:59"};
			grid.datagrid("options").pageNumber = 1;
			grid.datagrid('getPager').pagination({pageNumber:1});
			grid.datagrid('reload');
		}
  		/* 执行常规查询 */
  		function normalQuery(value,name){
  			grid.datagrid('load',{
  				queryField : name,
				queryValue : encodeURI(value)
			});
  		}
  		/* 显示全部记录 */
  		function displayAll(){
  			grid.datagrid('load',{});
  		}
  		/* 删除单条数据 */
  		function deleteRow(index){
			$.messager.confirm('提示','您是否确认执行删除操作？',function(r){
				if (r){
					var row = grid.datagrid('getRows')[index];
					if(row.id != ""){
						var url = "<%=cp%>/rbac/delOperLogById/"+row.id;
						$.post(
							url,
							function(msg) {
								$.messager.show({
									title:'提示',
									msg:'系统日志记录删除成功。',
									timeout:3000,
									showType:'fade'
								});
								grid.datagrid('deleteRow', index);
								grid.datagrid('reload');
							}
						);
					}
				}
			});
		}
  		/* 清空所有日志 */
  		function deleteAllRows(){
  			$.messager.confirm('提示','您是否确认执行清空日志操作？',function(r){
  				if(r){
					var url = "<%=cp%>/rbac/delAllOperLog";
					$.post(
						url,
						function(msg) {
							$.messager.show({
								title:'提示',
								msg:'系统日志记录已清空。',
								timeout:3000,
								showType:'fade'
							});
							grid.datagrid('reload');
						}
					);
				}
			});
  		}
  	</script>
  </head>
  <body style="margin:0px;" id="c_body">
  	<!-- DataGrid -->
	<table id="tt"></table>
	<div id="mm" style="width:120px;"></div>
	<input id="q" class="easyui-searchbox" prompt="按字段查询" searcher="normalQuery" style="width:200px; margin:5px;"></input>
	<!-- search form -->
	<div id="searchform" class="easyui-window" closed="true" modal="true">
	  <form id="search_form" method="post" style="margin:0; padding:0;">
		<table width="100%" cellspacing="1" cellpadding="2" border="0" align="center">
		  <tr>
			<td align="center" height="60">操作开始时间：<input id="btime" class="easyui-datebox" editable="false" /><br/>操作结束时间：<input id="etime" class="easyui-datebox" editable="false" /></td>
		  </tr>
		  <tr>
		    <td align="center"><a class="easyui-linkbutton" icon="icon-search" href="javascript:void(0)" onclick="do_search()">查询</a></td>
		  </tr>
		</table>
	  </form>
	</div>
	<!-- data item form -->
	<div id="data_win" class="easyui-window" closed="true" modal="true">
	    <div style="text-align:center; padding:1px;">
	        <form id="data_form" method="post">
	            <table width="90%" cellspacing="1" cellpadding="2" border="0" align="center">
	                <tr>
	                    <td>登录用户名：</td>
	                    <td><input type="text" name="loginUname" value="" readonly /></td>
	                    <td>登录用户ID：</td>
	                    <td><input type="text" name="loginUid" value="" readonly /></td>
	                </tr>
	                <tr>
	                    <td>操作时间：</td>
	                    <td><input type="text" name="operTime" value="" readonly /></td>
	                    <td>访问模块：</td>
	                    <td><input type="text" name="operMod" value="" readonly /></td>
	                </tr>
	                <tr>
	                    <td>事件：</td>
	                    <td><input type="text" name="operEvent" value="" readonly /></td>
	                    <td>IP地址：</td>
	                    <td><input type="text" name="operIp" value="" readonly /></td>
	                </tr>
	                <tr>
	                    <td>请求来源：</td>
	                    <td colspan="3"><textarea name="operFrom" cols="30" rows="5" style="width:100%;" readonly></textarea></td>
	                </tr>
	                <tr>
	                    <td>POST数据集合：</td>
	                    <td colspan="3"><textarea name="operPost" cols="30" rows="5" style="width:100%;" readonly></textarea></td>
	                </tr>
	                <tr>
	                    <td>GET数据集合：</td>
	                    <td colspan="3"><textarea name="operGet" cols="30" rows="5" style="width:100%;" readonly></textarea></td>
	                </tr>
	                <tr>
	                    <td>操作说明：</td>
	                    <td colspan="3"><textarea name="operRemark" cols="30" rows="5" style="width:100%;" readonly></textarea></td>
	                </tr>
	            </table>
	        </form>
	    </div>
	    <div style="text-align:center;padding:5px;"> 
	        <a href="javascript:void(0)" onclick="closeWindow()" id="btn-cancel" class="easyui-linkbutton" icon="icon-cancel">关闭</a>  
	    </div>  
	</div>
  </body>
</html>